package buco.jsonrpc;

import java.io.IOException;
import java.io.Writer;

import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import buco.core.api.RequireBundleRequirement;
import buco.core.api.VersionRange;

public class RequireBundleRequirementConverter implements JSONStreamAware {

	RequireBundleRequirement req; 
	
	public RequireBundleRequirementConverter(RequireBundleRequirement req) {
		this.req = req; 
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void writeJSONString(Writer wr) throws IOException {
		JSONObject reqJson = new JSONObject(); 
		reqJson.put("type", RequireBundleRequirement.class.getSimpleName());		
		reqJson.put("bundleSymbolicName", req.getBundleSymbolicName()); 
		VersionRange range = req.getBundleVersion();
		if(range != null) { 
			reqJson.put("bundleVersionRange", range.toString()); 
		}
		reqJson.writeJSONString(wr); 		
	}

}
